﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxEditors;

namespace Project_Udrinkwater.PagesAdmin
{
    public partial class Show_AllDataEmp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void bt_AddEmployee_Click(object sender, EventArgs e)
        {
            Response.Redirect("Register.aspx");
        }

        protected void CB_Province_SelectedIndexChanged(object sender, EventArgs e)
        {
            ASPxComboBox combo1 = (ASPxComboBox) sender;
            object oldCat1 = Session["Pro_ID"];
            if (oldCat1 != null && oldCat1.Equals(combo1.Value)) return;
            Session["Pro_ID"] = combo1.Value;
            //ASPxComboBox combo2 = ((ASPxComboBox) DetailGrid.FindEditRowCellTemplateControl(
            //DetailGrid.Columns["Order_Category_ID"] as GridViewDataComboBoxColumn, "cmbOrdercate"));
            ASPxComboBox combo2 = ((ASPxComboBox) GV_ShowdataEmp.FindEditFormTemplateControl("CB_Aumphur"));
            combo2.Value = null;

            CB_Aumphur_SelectedIndexChanged(combo2, EventArgs.Empty);
        }

        protected void CB_Aumphur_SelectedIndexChanged(object sender, EventArgs e)
        {
            ASPxComboBox combo2 = (ASPxComboBox) sender;
            object oldCat2 = Session["Aumphur_ID"];
            if (oldCat2 != null && oldCat2.Equals(combo2.Value)) return;
            Session["Aumphur_ID"] = combo2.Value;
            //ASPxComboBox combo3 = ((ASPxComboBox)DetailGrid.FindEditRowCellTemplateControl(
            //    DetailGrid.Columns["Price_Unit"] as GridViewDataComboBoxColumn, "cmbPrice"));
            ASPxComboBox combo3 = ((ASPxComboBox) GV_ShowdataEmp.FindEditFormTemplateControl("CB_District"));
            combo3.Value = null;

            CB_District_SelectedIndexChanged(combo2, EventArgs.Empty);
        }

        protected void CB_District_SelectedIndexChanged(object sender, EventArgs e)
        {
            ASPxComboBox combo2 = (ASPxComboBox) sender;
            object oldCat2 = Session["Aumphur_ID"];
            if (oldCat2 != null && oldCat2.Equals(combo2.Value)) return;
            Session["Aumphur_ID"] = combo2.Value;
            //ASPxComboBox combo3 = ((ASPxComboBox)DetailGrid.FindEditRowCellTemplateControl(
            //    DetailGrid.Columns["Price_Unit"] as GridViewDataComboBoxColumn, "cmbPrice"));
            ASPxComboBox combo3 = ((ASPxComboBox) GV_ShowdataEmp.FindEditFormTemplateControl("CB_District"));
            combo3.Value = null;
        }

        protected void GV_ShowdataEmp_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
        {
            e.NewValues["Prefix"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_Prefix")).Text;
            e.NewValues["FirstName"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_name")).Text;
            e.NewValues["LastName"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_lname")).Text;
            e.NewValues["Address"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_Address")).Text;
            e.NewValues["Tel"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_tel")).Text;
            e.NewValues["Salary"] = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_salary")).Text;
            e.NewValues["Department_Name"] = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("cb_department")).Value;
            e.NewValues["StartJob"] = ((ASPxDateEdit)GV_ShowdataEmp.FindEditFormTemplateControl("dateedit")).Value;
            e.NewValues["PROVINCE_ID"] = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_Province")).Value;
            e.NewValues["DISTRICT_ID"] = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_District")).Value;
            e.NewValues["AMPHUR_ID"] = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_Aumphur")).Value;
        }

        protected void GV_ShowdataEmp_HtmlEditFormCreated(object sender,DevExpress.Web.ASPxGridView.ASPxGridViewEditFormEventArgs e)
        {
            ASPxComboBox combo2 = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_Province") as ASPxComboBox);
            if (Request.Params[combo2.UniqueID] != null) return;
            if (!GV_ShowdataEmp.IsNewRowEditing)
            {
                object[] vals = (object[])GV_ShowdataEmp.GetRowValues(GV_ShowdataEmp.EditingRowVisibleIndex, new string[]
                        {
                            "Employee_ID","Prefix","FirstName","LastName","Address","Tel","Salary",
                            "PROVINCE_NAME","DISTRICT_NAME","AMPHUR_NAME","Department_Name","StartJob"
                        });

                ASPxComboBox combo5 = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("cb_department") as ASPxComboBox);
                ASPxComboBox combo3 = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_District") as ASPxComboBox);
                ASPxComboBox combo4 = ((ASPxComboBox)GV_ShowdataEmp.FindEditFormTemplateControl("CB_Aumphur") as ASPxComboBox);
                ASPxDateEdit date1 = ((ASPxDateEdit)GV_ShowdataEmp.FindEditFormTemplateControl("dateedit") as ASPxDateEdit);
                ASPxTextBox txt1 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_lname")) as ASPxTextBox;
                ASPxTextBox txt2 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_Address")) as ASPxTextBox;
                ASPxTextBox txt3 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_tel")) as ASPxTextBox;
                ASPxTextBox txt4 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_salary")) as ASPxTextBox;
                ASPxTextBox txt5 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_prefix")) as ASPxTextBox;
                ASPxTextBox txt6 = ((ASPxTextBox)GV_ShowdataEmp.FindEditFormTemplateControl("tb_name")) as ASPxTextBox;

                combo2.Value = vals[7].ToString();
                combo3.Value = vals[9];
                combo4.Value = vals[8];
                combo5.Value = vals[10];
                date1.Value = vals[11];
                txt1.Text = vals[3].ToString();
                txt2.Text = vals[4].ToString();
                txt3.Text = vals[5].ToString();
                txt4.Text = vals[6].ToString();
                txt5.Text = vals[1].ToString();
                txt6.Text = vals[2].ToString();
            }


        }
    }
}